package com.yuanlrc.base.controller.admin;

import com.yuanlrc.base.bean.Result;
import com.yuanlrc.base.entity.admin.BookNameCount;
import com.yuanlrc.base.entity.admin.BorrowAmount;
import com.yuanlrc.base.entity.admin.StudentNameCount;
import com.yuanlrc.base.service.admin.QuantityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 统计的控制器
 */
@RequestMapping(value="/quantity")
@Controller
public class QuantityController {
    @Autowired
    private QuantityService quantityService;

    /**
     * 图书借阅统计 获取数据
     * @return
     */
    @GetMapping("/bookCount")
    @ResponseBody
    //返回集合数据
   public Result<List<BookNameCount>> findBookNameCount(){
      List<BookNameCount> bookNameCountList = quantityService.findBookNameCount();
      return Result.success(bookNameCountList);
   }
    @RequestMapping(value="/book")
    public String Book(Model model){
        model.addAttribute("title", "图书借阅列表");
        return "admin/quantity/book";
    }
    //返回集合数据
    @GetMapping("/studentCount")
    @ResponseBody
    public Result<List<StudentNameCount>> findStudentNameCount(){
        List<StudentNameCount> studentNameCountList = quantityService.findStudentNameCount();
        return Result.success(studentNameCountList);
    }

    @RequestMapping(value="/student")
    public String Studnet(Model model){
        model.addAttribute("title", "学生借阅列表");
        return "admin/quantity/student";
    }
    //返回集合数据
    @GetMapping("/borrowAmount")
    @ResponseBody
    public Result<List<BorrowAmount>> findStudentBorrowNum(){
        List<BorrowAmount> borrowAmountList = quantityService.findStudentBorrowNum();
        return Result.success(borrowAmountList);
    }
    @RequestMapping(value="/borrow")
    public String borrowNum(Model model) {

        model.addAttribute("title", "学生借阅数量列表");
        return "admin/quantity/borrows";
    }

}
